﻿using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    /// <summary>
    /// 数据访问类
    /// </summary>
    public class StudentService
    {
        public List<Students> GetStudent(int classId)
        {
            using (EFDBEntities db = new EFDBEntities())
            {
                var stuList = from s in db.Students
                              where s.ClassId == classId
                              select new
                              {
                                  s.StudentId,
                                  s.StudentName,
                                  s.Gender,
                                  s.Age,
                                  s.PhoneNumber
                              };
                List<Students> list = new List<Students>();
                foreach (var item in stuList)
                {
                    list.Add(new Students
                    {
                        StudentId = item.StudentId,
                        StudentName = item.StudentName,
                        Gender = item.Gender,
                        Age = item.Age,
                        PhoneNumber = item.PhoneNumber
                    });
                }
                return list;
            }
        }
    }
}
